jQ(function(){
	initHeadButton();
	analyzeUrl();
	initContactGroups();
	jQ("#ALERT").dialog({
		modal: true,
		bgiframe: true,
		autoOpen: false,
		resizable:false,
		closeOnEscape:false,
		draggable:true,
		buttons: {
			"确定": function() {
				jQ(this).trigger("LFun");
				jQ(this).dialog('close');
			},
			"取消": function() {
				jQ(this).dialog('close');
			}
		},
		close: function() {},
		open:function(){}
	});
	jQ("span.share-title input[name=shareraido]:first").click();
	jQ("span.share-title input[name=shareraido]").click(function(){
		var val=eval(jQ(this).val());
		if(val){
			jQ("#share-contactchoose").fadeIn();
		}else{
			jQ("#share-contactchoose").fadeOut();
		}
	});
});


function initContactGroups(){
	jQ.ajax({
		type:"POST",
		url: "contactAjax!getExistGroupAndContacts.action",
		success:function(data){
			if(data!=null){
				var source = jQ( "ContactGroup ", data ).map(function() {
					return {
						label: jQ("groupname", this).text(),
						id: jQ(this).attr("id"),
						membercount: jQ("membercount", this).text(),
						value:jQ("pinyingroupname", this).text()
					};
				}).get();
				jQ( "#shareautoipt" ).autocomplete({
					source: source,
					minLength:1,
					select: function( event, ui ) {
						if(ui.item){
							showQuickContactGroup(ui.item.id,ui.item.label,ui.item.membercount);
						}
					},
					close: function() {
						jQ( "#shareautoipt" ).val("");
					}
				}).data( "autocomplete" )._renderItem = function( ul, item ) {
				return jQ( "<li></li>" )
					.data( "item.autocomplete", item )
					.append( "<a>" + item.label +"</a>" )
					.appendTo( ul );
				};
				
			}
		}
	});
	
}


function showQuickContactGroup(id,name,membercount){
	var flag=false;
	if(jQ("#contactgrouplist").css("display")=="none"){
		flag=true;
	}
	var canbeadd=true;
	jQ("li",jQ("#contactgrouplist")).each(function(){
		var groupid=eval(jQ(this).attr("groupid"));
		if(groupid==eval(id)){
			canbeadd=false;
			return false;
		}
	});
	if(!canbeadd)
		return;
	var countstr;
	if(membercount>99){
		countstr=membercount+"+";
	}else{
		countstr=membercount;
	}
	var html="<li groupid='"+id+"'>";
	html+="<span class=\"groupicon\"></span>";
	html+="<span class=\"groupname\">"+name+"</span>";
	html+="<span class=\"groupcount\">["+countstr+"]</span>";
	html+="<a onclick='deleteContactGroup(this);'></a></li>";
	jQ("#contactgrouplist").append(html);
	if(jQ("#contactgrouplist").css("display")=="none"){
		jQ("#contactgrouplist").show();
	}
}

function deleteContactGroup(obj){
	var groupid=jQ(obj).parent().attr("groupid");
	var li=jQ("#contactgroup li[groupid="+groupid+"]");
	li.find("input:checkbox").attr("checked",false);
	jQ(obj).parent().remove();
	if(jQ("li",jQ("#contactgrouplist")).length==0){
		jQ("#contactgrouplist").hide();
	}
}

function initHeadButton(){

	jQ("#share_clips").mouseover(function(){
		jQ(this).css({"backgroundPosition":"0px -33px"});
	});
	jQ("#share_clips").mouseout(function(){
		jQ(this).css({"backgroundPosition":"0px 0px"});
	});
	
	jQ("#person_contacts").mouseover(function(){
		jQ(this).css({"backgroundPosition":"-239px -33px"});
	});
	jQ("#person_contacts").mouseout(function(){
		jQ(this).css({"backgroundPosition":"-239px 0px"});
	});
	
	jQ("#question_apply").mouseover(function(){
		jQ(this).css({"backgroundPosition":"-405px -33px"});
	});
	jQ("#question_apply").mouseout(function(){
		jQ(this).css({"backgroundPosition":"-405px 0px"});
	});
	
	jQ("#my_clips").mouseover(function(){
		jQ("#my_clipscontent").show();
		jQ("#my_clips a.btn").css({"backgroundPosition":"-75px -33px"});
	});
	jQ("#my_clips").mouseout(function(){
		jQ("#my_clipscontent").hide();
		jQ("#my_clips a.btn").css({"backgroundPosition":"-75px 0px"});
	});
	jQ("#person_controls").mouseover(function(){
		jQ("#person_controlscontent").show();
		jQ("#person_controls a.btn").css({"backgroundPosition":"-157px -33px"});
	});
	jQ("#person_controls").mouseout(function(){
		jQ("#person_controlscontent").hide();
		jQ("#person_controls a.btn").css({"backgroundPosition":"-157px 0px"});
	});
	jQ("#person_contacts").mouseover(function(){
		jQ("#person_contactscontent").show();
		jQ("#person_contacts a.btn").css({"backgroundPosition":"-239px -33px"});
	});
	jQ("#person_contacts").mouseout(function(){
		jQ("#person_contactscontent").hide();
		jQ("#person_contacts a.btn").css({"backgroundPosition":"-239px 0px"});
	});
	jQ("#user_apply").mouseover(function(){
		jQ("#user_applycontent").show();
		jQ("#user_apply a.btn").css({"backgroundPosition":"-323px -33px"});
	});
	jQ("#user_apply").mouseout(function(){
		jQ("#user_applycontent").hide();
		jQ("#user_apply a.btn").css({"backgroundPosition":"-323px 0px"});
	});
}


function confirmshare(){
	var canforward=eval(jQ("#clipevent-opt").data("canforward"));
	if(canforward){
		var sharecbxval=jQ('input[name=shareraido]:checked').val();
		if(eval(sharecbxval)){
			var templength=jQ("li",jQ("#contactgrouplist")).length;
			errzone=jQ("#share-errorinfo");
			if(templength==0){
				errzone.empty();
				errzone.append("请至少选择一个指定群组。");
				errzone.show();
				return;
			}else{
				errzone.empty();
			}
			
		}
		var sharelist='';
		
		var sharecbxval=jQ('input[name=shareraido]:checked').val();
		if(eval(sharecbxval)){
			var tmphtml="";
			jQ("#contactgrouplist li").each(function(i){
				if(i==0)
					tmphtml=jQ(this).attr("groupid");
				else{
					tmphtml+=","+jQ(this).attr("groupid");
				}
			});
			sharelist=tmphtml;
		}else{
			sharelist="0";
		}
		var eventid=jQ("#clip-contentlist").data("eventid");
		jQ.ajax({
			type: "POST",
			url:"shareAjax!forwardShareEvent.action",
			data:{
				eventid:eval(eventid),
				sharelist:sharelist
			},
			success:function(data){
				if(data!=null){
					var dataObj=eval("("+data+")");//转换为json对象
					if(dataObj.result){
						alert("转发成功");
						var shareid=dataObj.shareid;
						jQ("#shareoutzone").show();
						jQ("#shareoutzone").data("acceptshareid",shareid);
						jQ("#forwardshare_box").fadeOut();
					}else{
						alert(dataObj.msg);
						window.location.reload();
					}
				}
			}
		});
	}
}
function cancelshare(){
	var canforward=eval(jQ("#clipevent-opt").data("canforward"));
	if(canforward)
		jQ("#forwardshare_box").toggle();
}


function analyzeUrl(){
	var uuid=getUniqueParameter();
	if(uuid!=null&&uuid.length==32){
		checkExistUser();
		loadShareEvent(uuid);
	}else{
		window.location.href=jQ("#ctxVal").val()+"/index.html";
	}
}

function loadShareEvent(uuid){
	
	jQ.ajax({
		type: "POST",
		url:"shareAjax!loadShareEvent.action",
		data:{
			shareid:uuid
		},
		success:function(data){
			if(data!=null&&typeof(data)!='string'){
				jQ("#clipevent-errorcontent").hide();
				
				var eventid=eval(jQ(data).find("ShareEvent").attr("id"));
				loadClipMessage(eventid);
				
				var event=jQ(data).find("ShareEvent");
				var title=event.find("title").text();
				var eventtype=event.find("eventtype").text();
				var starttime=eval(event.find("starttime").text());
				var endtime=eval(event.find("endtime").text());
				var iswholeday=eval(event.find("iswholeday").text());
				var address=event.find("address").text();
				var content=event.find("content").text();
				var processstatus=eval(event.find("processstatus").text());
				var reliedclip=eval(event.find("reliedclip").text());
				var uname=event.find("uname").text();
				var pname=event.find("pname").text();
				var shareid=event.find("shareid").text();
				var isself=eval(event.find("isself").text());
				var isaccept=false;
				var countsharesave=eval(event.find("countsharesave").text());
				var countshareforward=eval(event.find("countshareforward").text());
				if(reliedclip>0)
					loadCurrentUserContactInShare(reliedclip);
				else
					loadCurrentUserContactInShare(eventid);
				if(reliedclip>0){
					jQ("#reliedclipsavenum").empty().append(countsharesave);
					jQ("#reliedclipsavenum").parent().show();
					jQ("#reliedclipforwardnum").empty().append(countshareforward);
					jQ("#reliedclipforwardnum").parent().show();
					jQ("#savesharenum").parent().hide();
					jQ("#forwardsharenum").parent().hide();
				}else{
					jQ("#savesharenum").empty().append(countsharesave);
					jQ("#forwardsharenum").empty().append(countshareforward);
					jQ("#reliedclipsavenum").parent().hide();
					jQ("#reliedclipforwardnum").parent().hide();
				}
				/*jQ("#invitednum").empty().append(allcount);*/
				var joincount=0;
				var rejectcount=0;
				var joinH="";
				var refuseH="";
				var no_joinH="";
				jQ(data).find("ShareEvent").find("contact").each(function(){
					
				});
				/*if(joinH.length==0&&refuseH.length==0&&no_joinH.length==0){
					jQ("#clipevent-contacts").empty().append("<li style='width:188px;'><i>暂无成员</i></li>");
				}else{
					jQ("#clipevent-contacts").empty().append(joinH).append(refuseH).append(no_joinH);
				}
				jQ("#joinednum").empty().append(joincount);
				jQ("#refusednum").empty().append(rejectcount);*/
				
				jQ("#clip-contentlist").data("eventid",eventid);
				jQ("#clip-contentlist").data("shareid",shareid);
				jQ("#clip-contentlist").data("title",title);
				jQ("#clip-contentlist").data("starttime",starttime);
				jQ("#event-title").empty().append(title);
				
				if(reliedclip==0){
					jQ("#event-uname").parent().hide();
					jQ("#event-pname").empty().append(uname);
					var unamelogo=event.find("unamelogo").text();
					jQ("#event-pnamelogo").css({"background":"url('"+unamelogo+"')"});
					if(eval(jQ("#userloginbutton").data("isuser"))){
						var unameid=event.find("unameid").text();
						jQ("#event-pname").unbind("mouseover").bind("mouseover",function(){
							jQ(this).css({ "text-decoration": "underline"});
						});
						jQ("#event-pname").unbind("mouseout").bind("mouseout",function(){
							jQ(this).css({ "text-decoration": "none"});
						});
						jQ("#event-pname").unbind("click").bind("click",function(){
							window.location.href=jQ("#ctxVal").val()+"/myclip/user.html?"+unameid;
						});
						jQ("#event-pnamelogo").unbind("click").bind("click",function(){
							window.location.href=jQ("#ctxVal").val()+"/myclip/user.html?"+unameid;
						});
					}
					
				}else{
					jQ("#event-uname").empty().append(uname).parent().show();
					jQ("#event-pname").empty().append(pname);
					var unamelogo=event.find("unamelogo").text();
					var pnamelogo=event.find("pnamelogo").text();
					jQ("#event-unamelogo").css({"background":"url('"+unamelogo+"')"});
					jQ("#event-pnamelogo").css({"background":"url('"+pnamelogo+"')"});
					if(eval(jQ("#userloginbutton").data("isuser"))){
						var pnameid=event.find("pnameid").text();
						jQ("#event-pname").unbind("mouseover").bind("mouseover",function(){
							jQ(this).css({ "text-decoration": "underline"});
						});
						jQ("#event-pname").unbind("mouseout").bind("mouseout",function(){
							jQ(this).css({ "text-decoration": "none"});
						});
						jQ("#event-pname").unbind("click").bind("click",function(){
							window.location.href=jQ("#ctxVal").val()+"/myclip/user.html?"+pnameid;
						});
						jQ("#event-pnamelogo").unbind("click").bind("click",function(){
							window.location.href=jQ("#ctxVal").val()+"/myclip/user.html?"+pnameid;
						});
						var unameid=event.find("unameid").text();
						jQ("#event-uname").unbind("mouseover").bind("mouseover",function(){
							jQ(this).css({ "text-decoration": "underline"});
						});
						jQ("#event-uname").unbind("mouseout").bind("mouseout",function(){
							jQ(this).css({ "text-decoration": "none"});
						});
						jQ("#event-uname").unbind("click").bind("click",function(){
							window.location.href=jQ("#ctxVal").val()+"/myclip/user.html?"+unameid;
						});
						jQ("#event-unamelogo").unbind("click").bind("click",function(){
							window.location.href=jQ("#ctxVal").val()+"/myclip/user.html?"+unameid;
						});
					}
				}
				
				
				jQ("#event-type").empty().append("<i class='"+eventtype+"'></i>"+getTypeName(eventtype));
				if(iswholeday)
					jQ("#event-time").empty().append("<span style='width:auto;padding-top:0px;'>开始于</span><b>"+formateDetailTimeWithhourmin(starttime)+"</b>");
				else
					jQ("#event-time").empty().append("<b>"+formateDetailTimeWithhourmin(starttime)+"</b><b>至</b><b>"+formateDetailTimeWithhourmin(endtime)+"</b>");
				if(processstatus==0){
					jQ("#event-processtatus").removeClass().addClass("edt_ing").empty().append("进行中");
				}else if(processstatus==1){
					jQ("#event-processtatus").removeClass().addClass("edt_over").empty().append("已结束");
				}else if(processstatus==2){
					jQ("#event-processtatus").removeClass().addClass("edt_stop").empty().append("已停止");
				}
				
				
				if(address.length>0){
					jQ("#event-address").empty().append(htmlData(address));
					jQ("#event-address").parent().show();
				}else
					jQ("#event-address").parent().hide();
				if(content.length>0){
					jQ("#event-detail").empty().append(content).show();
					jQ("#event-detail").parent().show();
				}else
					jQ("#event-detail").parent().hide();
				jQ("#clipevent-opt a").unbind("click");
				if(processstatus!=0){
					jQ("#clipevent-opt a.over").show();
				}
				if(isself){
					jQ("#clipevent-opt a.forwardshare").show();
					jQ("#clipevent-opt").data("canforward",true);
					jQ("#clipevent-opt").data("cansave",false);
				}else{
					var isuser=eval(jQ("#userloginbutton").data("isuser"));
					if(isuser){
						isaccept=eval(event.find("isaccept").text());
						if(isaccept){
							jQ("#clipevent-opt a.forwardshare").show();
							jQ("#clipevent-opt").data("canforward",true);
							jQ("#clipevent-opt").data("cansave",false);
							jQ("#shareoutzone").data("acceptshareid",event.find("acceptshareid").text());
						}else{
							jQ("#clipevent-opt a.saveshare").show();
							jQ("#clipevent-opt").data("canforward",false);
							jQ("#clipevent-opt").data("cansave",true);
						}
					}
				}
				if(isself||isaccept){
					
					if(event.find("sharemembers").length>0){
						jQ("#clipevent-opt a.alreadyfw").show().unbind("click").bind("click",alreadyfwEvent);
						var tempnamehtml="";
						var shareall=event.find("sharemembers[index=-1]");
						if(shareall.length>0){
							var logo=shareall.text();
							var name=shareall.attr("name");
							tempnamehtml="<div class=\"forwardmember\" uid='0'><div class=\"logo\" style=\"background:url('"+logo+"')\"></div><span class=\"name\">"+name+"</span></div>";
						}else{
							event.find("sharemembers").each(function(i){
								var logo=jQ(this).text();
								var name=jQ(this).attr("name");
								var uid=jQ(this).attr("uid");
								tempnamehtml+="<div class=\"forwardmember\" uid='"+uid+"'>" +
										"<div class=\"logo\" style=\"background:url('"+logo+"')\">" +
										"</div><span class=\"name\">"+name+"</span></div>";
							});
						}
						jQ("#forwardsharemember_body").empty().append(tempnamehtml);
						jQ("#forwardsharemember_body div.forwardmember").bind("click",function(){
							var uid=jQ(this).attr("uid");
							if(uid>0)
								window.location.href=jQ("#ctxVal").val()+"/myclip/user.html?"+uid;
						});
					}
				}
				//initDetailTimeSelect();
				initDetailOptBtn();
				jQ("#clipevent-maincontent").show();
				
			}else{
				jQ("#clipevent-maincontent").hide();
				var isuser=eval(jQ("#userloginbutton").data("isuser"));
				if(isuser){
					jQ("#clipevent-errorcontent button.backhome").show().unbind("click").bind("click",function(){
						window.location.href=jQ("#ctxVal").val()+"/home/";
					});
				}else{
					jQ("#clipevent-errorcontent button.backregister").show().unbind("click").bind("click",function(){
						window.location.href=jQ("#ctxVal").val()+"/register.html";
					});
				}
				jQ("#clipevent-errorcontent").show();
				//jQ("#clipevent-title").empty().append("<i style='color:#ff0000;'>对不起，该档期不存在或您无权访问。</i>")
			}
		}
	});
}

function alreadyfwEvent(){
	if(jQ(this).hasClass("alreadyfwopen")){
		jQ(this).removeClass("alreadyfwopen").addClass("alreadyfw");
		jQ("#forwardsharemember_box").hide();
	}else{
		jQ(this).removeClass("alreadyfw").addClass("alreadyfwopen");
		var offset=jQ(this).offset();
		jQ("#forwardsharemember_box").css({"left":offset.left+80,"top":offset.top});
		jQ("#forwardsharemember_box").show();
	}
}

function closeForwardsharemember_box(){
	jQ("#clipevent-opt a.alreadyfwopen").removeClass("alreadyfwopen").addClass("alreadyfw");
	jQ("#forwardsharemember_box").hide();
}

function loadCurrentUserContactInShare(eventid){
	if(eval(jQ("#userloginbutton").data("isuser"))){
		jQ.ajax({
			type: "POST",
			url:"shareAjax!loadsfFriends.action",
			data:{
				eventid:eval(eventid)
			},
			success:function(data){
				if(data!=null){
					var length=jQ(data).find("User").length;
					jQ("#friendscount").empty().append(length);
					if(length==0){
						jQ("#checkfriendsbtn").hide();
					}else{
						var html="";
						jQ(data).find("User").each(function(i){
							var nickname=jQ(this).find("nickname").text();
							var realname=jQ(this).find("realname").text();
							var uid=jQ(this).attr("uid");
							if(i<6){
								html+="<li index="+i+" class=\"list\">";
							}else{
								html+="<li style='display:none;' index="+i+" class=\"list\">";
							}
							html+="<a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"'>";
							html+="<span class='nickname'>"+nickname+"</span>";
							html+="<span class='out'>( <span class='realname'>"+realname+"</span> )</span>";
							html+="</a>";
							html+="</li>";
						});
						if(jQ(data).find("User").length>6){
							html+="<li class=\"paging\"><a class=\"next\" title=\"下页\"></a><a class=\"prev\" title=\"上页\"></a></li>";
						}
						jQ("#friendslist").empty().append(html).hide();
						if(jQ(data).find("User").length>6){
							var maxcount=jQ(data).find("User").length;
							jQ("#friendslist").data("page",0);
							jQ("#friendslist").data("maxcount",maxcount);
							jQ("#friendslist").data("maxpage",Math.ceil(maxcount/6));
							jQ("#friendslist li.paging a.next").unbind("click").bind("click",shareFriendsNextPage);
							jQ("#friendslist li.paging a.prev").unbind("click").bind("click",shareFriendsPrevPage);
						}
						jQ("#checkfriendsbtn").show().unbind("click").bind("click",showfriendsaboutshare);
					}
				}
			}
		});
	}
}

function shareFriendsNextPage(){
	var page=eval(jQ("#friendslist").data("page"));
	var maxpage=eval(jQ("#friendslist").data("maxpage"));
	var maxcount=eval(jQ("#friendslist").data("maxcount"));
	if(page+1>=maxpage){
		return;
	}else{
		for(var i=0;i<6;i++){
			var index=page*6+i;
			jQ("#friendslist li[index="+index+"]").fadeOut("normal",function(){
				var temp=eval(jQ(this).attr("index"));
				if(temp+6<maxcount){
					jQ("#friendslist li[index="+(temp+6)+"]").fadeIn();
				}
			});
		}
		jQ("#friendslist").data("page",page+1);
	}
}

function shareFriendsPrevPage(){
	var page=eval(jQ("#friendslist").data("page"));
	var maxcount=eval(jQ("#friendslist").data("maxcount"));
	if(page-1<0){
		return;
	}else{
		var index=page*6;
		for(var i=5;i>=0;i--){
			var index=page*6+i;
			if(index>=maxcount){
				jQ("#friendslist li[index="+(index-6)+"]").fadeIn();
			}
			jQ("#friendslist li[index="+index+"]").fadeOut("normal",function(){3
				var temp=eval(jQ(this).attr("index"));
				if(temp-6>=0){
					jQ("#friendslist li[index="+(temp-6)+"]").fadeIn();
				}
			});
		}
		jQ("#friendslist").data("page",page-1);
	}
	
}

function showfriendsaboutshare(){
	if(jQ("#checkfriendsbtn").hasClass("checkfriendsopened")){
		jQ("#checkfriendsbtn").removeClass("checkfriendsopened");
		jQ("#friendslist").hide();
	}else{
		jQ("#checkfriendsbtn").addClass("checkfriendsopened");
		jQ("#friendslist").show();
	}
}

function forwardshare(){
	position2where(jQ("#forwardshare_box"),jQ(this));
	jQ("#forwardshare_box").show();
}

function initDetailOptBtn(){
	var canforward=eval(jQ("#clipevent-opt").data("canforward"));
	var cansave=eval(jQ("#clipevent-opt").data("cansave"));
	if(canforward){
		jQ("#clipevent-opt a.forwardshare").one("click",forwardshare);
		var acceptshareid=jQ("#shareoutzone").data("acceptshareid");
		if(acceptshareid.length>0){
			jQ("#shareoutzone").show();
		}
		initShareOutofSite();
	}
	if(cansave){
		jQ("#clipevent-opt a.saveshare").one("click",function(){
			var eventid=jQ("#clip-contentlist").data("eventid");
			jQ.ajax({
				type: "POST",
				url:"shareAjax!saveShareEvent.action",
				data:{
					eventid:eval(eventid)
				},
				success:function(data){
					if(data!=null){
						var dataObj=eval("("+data+")");//转换为json对象
						if(dataObj.result){
							alert("保存成功");
							jQ("#clipevent-opt").data("cansave",false);
							jQ("#clipevent-opt").data("canforward",true);
							jQ("#clipevent-opt a.forwardshare").show();
							jQ("#clipevent-opt a.saveshare").hide();
							jQ("#clipevent-opt a").unbind("click");
							jQ("#clipevent-opt a.forwardshare").bind("click",forwardshare);
						}else{
							alert(dataObj.msg);
							window.location.reload();
						}
					}
				}
			});
		});
	}
}

function initShareOutofSite(){
	jQ("#shareoutzone div.shareoutopt a").unbind("click");
	jQ("#shareoutzone div.shareoutopt a.renrenlogo").bind("click",function(){
		var shareid=jQ("#shareoutzone").data("acceptshareid");
		var title=jQ("#clip-contentlist").data("title");
		var starttime=eval(jQ("#clip-contentlist").data("starttime"));
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		
		
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/home/detail.html?"+shareid;
		window.open(
		'http://www.connect.renren.com/share/sharer?url='+url
		+'&title=档期分享：'+startstr+'  '+title+'    '+'更多详情请点击',
		'_blank',
		'height=290,width=510,top=200,left=430,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no'); 
	});
	
	jQ("#shareoutzone div.shareoutopt a.kaixin001logo").bind("click",function(){
		var shareid=jQ("#shareoutzone").data("acceptshareid");
		var title=jQ("#clip-contentlist").data("title");
		var starttime=eval(jQ("#clip-contentlist").data("starttime"));
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/home/detail.html?"+shareid;
		window.open(
		'http://www.kaixin001.com/repaste/share.php?rurl='+url
		+'&rtitle=档期分享'
		+'&rcontent='+startstr+'  '+title+'    '+'更多详情请点击',
		'_blank',
		'height=500,width=700,top=200,left=410,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
		
	});
	
	jQ("#shareoutzone div.shareoutopt a.sinalogo").bind("click",function(){
		var shareid=jQ("#shareoutzone").data("acceptshareid");
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/home/detail.html?"+shareid;
		var title=jQ("#clip-contentlist").data("title");
		var starttime=eval(jQ("#clip-contentlist").data("starttime"));
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		var param = {
		    url:url,
		    type:'3',
		    title:'档期分享：'+startstr+'  '+title+'    '+'更多详情请点击',
			language:'zh_cn',
		    rnd:new Date().valueOf()
		  }
		var temp = [];
		for( var p in param ){
			temp.push(p + '=' + encodeURIComponent( param[p] || '' ) )
		}
		
		window.open(
				'http://service.weibo.com/share/share.php?' + temp.join('&') ,
				'_blank',
		'height=520,width=607,top=150,left=410,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
	});
	jQ("#shareoutzone div.shareoutopt a.doubanlogo").bind("click",function(){
		var shareid=jQ("#shareoutzone").data("acceptshareid");
		var url="http://"+document.domain+jQ("#ctxVal").val()+"/home/detail.html?"+shareid;
		var title=jQ("#clip-contentlist").data("title");
		var starttime=eval(jQ("#clip-contentlist").data("starttime"));
		var day=new Date();
		day.setTime(starttime);
		var startstr=day.pattern("yyyy年MM月dd日");
		window.open(
		'http://www.douban.com/recommend/?url='+url
		+'&title=档期分享'+
		+'&comment='+startstr+'  '+title+'    '+'更多详情请点击',
		'_blank',
		'height=370,width=505,top=300,left=450,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no, status=no');
	});
}

function position2where(obj,posobj){
	var box = posobj.offset();
	var box_position = box.left + obj.width();
	obj.css({"top":box.top+25,"left":box.left-150});
}


function loadClipMessage(eventid){
	jQ.ajax({
		type: "POST",
		url:"eventAjax!loadClipMessage.action",
		data:{
			eventid:eval(eventid)
		},
		success:function(data){
			if(data!=null){
				if(jQ(data).find("Clipmessage").length==0){
					jQ("#clipevent-messages").empty();
					return;
				}
				var html="";
				jQ(data).find("Clipmessage").each(function(){
					var content=jQ("content",this).text();
					var email=jQ(this).find("email").text();
					var replytime=eval(jQ(this).find("replytime").text());
					var name=jQ(this).find("name").text();
					var uid=jQ(this).find("uid").text();
					var logo=jQ(this).find("logo").text();
					var replystr=formateDetailTimeWithhourmin(replytime);
					var tmp="<li class='leave_msg'>";
					tmp+="<dt>";
					tmp+="<a class='logo' style='background:url(\""+logo+"\")' href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"'></a>";
					tmp+="<span class='fid'>";
					tmp+="<a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"'>"+name+"</a>";
					tmp+="</span>";
					tmp+="<div>";
					tmp+=htmlData(content);
					tmp+="</div>";
					tmp+="<span class='time'>";
					tmp+=replystr;
					tmp+="</span></dt>";
					tmp+="</li>";
					html+=tmp;
				});
				jQ("#clipevent-messages").empty().append(html);
			}
		}
	});
}

function checkExistUser(){
	var url="userAjax!checkExistUser.action";
	jQ.ajax({
		type: "POST",
		url:url,
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['loginflag']){
					getMessageCount();
					jQ("#userloginbutton").data("isuser",1);
					jQ("#userloginbutton").empty().append("退出登录");
					jQ("#userloginbutton").unbind("click").bind("click",logout);
					jQ("#findfinfoclosebtn").unbind("click").bind("click",removefindfinfo);
					var name=dataObj["name"];
					var url=dataObj.url;
					jQ("#user_url").css("backgroundImage","url('"+url+"')");
					var check=eval(dataObj.invitefriendnotice);
					if(check==null||typeof check=="undefined"){
						jQ("#findfinfo").hide();
					}else{
						if(check==0)
							jQ("#findfinfo").show();
					}
					jQ("div.login_box span.user_name").empty();
					jQ("div.login_box span.user_name").append("<b id=\"user_name\">"+dataObj["name"]+"</b><b>"+dataObj["email"]+"</b>");
					jQ("div.login_box span.user_name").unbind("click").bind("click",function(){
						window.location.href=jQ("#ctxVal").val()+"/control/userinfo.html";
					});
					jQ("#login_systemtime").val(dataObj["systime"]);
					jQ("#var_hasmobile").val(dataObj.mobilenotice);
					var formatDate = "<li class=\"hour\">%H:%M</li><li class=\"data\"><span>%a</span><span>%m月%d日</span><span>%Y年</span></li>";
					var options1 = {
							format: formatDate,
							seedTime:eval(dataObj["systime"])
					}
					jQ('div.now_time ul').jclock(options1); 
					jQ("#clipevent-replyzone").show();
				}else{
					jQ("#userloginbutton").data("isuser",0);
					jQ("#userloginbutton").empty().append("用户注册");
					jQ("#user_url").css("backgroundImage","url(\""+jQ("#ctxVal").val()+"/image/clipsmall.jpg\")");
					jQ("div.login_box span.user_name").empty();
					jQ("div.login_box span.user_name").append("<b id=\"user_name\">游客</b>");
					jQ("#userloginbutton").unbind("click").bind("click",function(){
						window.location.href=jQ("#ctxVal").val()+"/register.html";
					});
					jQ("#findfinfoclosebtn").unbind("click").bind("click",function(){
						jQ("#findfinfo").hide();
					});
					jQ("#login_systemtime").val(dataObj["systime"]);
					var formatDate = "<li class=\"hour\">%H:%M</li><li class=\"data\"><span>%a</span><span>%m月%d日</span><span>%Y年</span></li>";
					var options1 = {
							format: formatDate,
							seedTime:eval(dataObj["systime"])
					}
					jQ('div.now_time ul').jclock(options1); 
					jQ("#clipevent-replyzone").hide();
				}
			}
		}
	});
}

function removefindfinfo(){
	var url="userAjax!cancelInviteFriendNotice.action";
	jQ.ajax({
		type: "POST",
		url:url,
		success:function(data){
			if(data!=null){
				var dataObj=eval("("+data+")");//转换为json对象
				if(dataObj['flag']){
					jQ("#findfinfo").hide();
				}else{
					window.location.href=jQ("#ctxVal").val()+"/index.html";
				}
			}
		}
	});
}

function logout(){
	jQ.ajax({
		type: "POST",
		url:"userAjax!logout.action",
		success:function(data){
			window.location.href=jQ("#ctxVal").val()+"/index.html";
		}
	});
}

function jalert(info,data,LFun){
	jQ("#ALERT").unbind();
	jQ("#ALERT p").html(info);
	if(LFun!=null)
		jQ("#ALERT").bind("LFun",data,LFun);
	jQ("#ALERT").dialog('open');
}

function getMessageCount(){
	jQ.get("messageAjax!getMsgCount.action",function(data){
		var count1 = eval(jQ(data).find("friend").text());
		var count2 = eval(jQ(data).find("alarm").text());
		var count3 = eval(jQ(data).find("invite").text());
		var count4 = eval(jQ(data).find("comment").text());
		if(count1>0){
			jQ("#personal_newmsg a.finvite").show().unbind("click").bind("click",function(){
				window.location.href=jQ("#ctxVal").val()+"/myclip/message.html?type=request";
			});
			jQ("#finvitecount").empty().append("("+count1+")").show().unbind("click").bind("click",function(){
				window.location.href=jQ("#ctxVal").val()+"/myclip/message.html?type=request";
			});
		}else{
			jQ("#personal_newmsg a.finvite").hide();
			jQ("#finvitecount").hide();
		}
		if(count2>0){
			jQ("#personal_newmsg a.cinvite").show().unbind("click").bind("click",function(){
				window.location.href=jQ("#ctxVal").val()+"/myclip/message.html?type=remind";
			});
			jQ("#cinvitecount").empty().append("("+count2+")").show().unbind("click").bind("click",function(){
				window.location.href=jQ("#ctxVal").val()+"/myclip/message.html?type=remind";
			});
		}else{
			jQ("#personal_newmsg a.cinvite").hide();
			jQ("#cinvitecount").hide();
		}
		if(count3>0){
			jQ("#personal_newmsg a.calert").show().unbind("click").bind("click",function(){
				window.location.href=jQ("#ctxVal").val()+"/myclip/clip_week.html";
			});
			jQ("#calertcount").empty().append("("+count3+")").show().unbind("click").bind("click",function(){
				window.location.href=jQ("#ctxVal").val()+"/myclip/clip_week.html";
			});
		}else{
			jQ("#personal_newmsg a.calert").hide();
			jQ("#calertcount").hide();
		}
		if(count4>0){
			jQ("#personal_newmsg a.ccomment").show().unbind("click").bind("click",function(){
				window.location.href=jQ("#ctxVal").val()+"/myclip/message.html?type=comment";
			});
			jQ("#ccommentcount").empty().append("("+count4+")").show().unbind("click").bind("click",function(){
				window.location.href=jQ("#ctxVal").val()+"/myclip/message.html?type=comment";
			});
		}else{
			jQ("#personal_newmsg a.ccomment").hide();
			jQ("#ccommentcount").hide();
		}
	});
	setTimeout(getMessageCount,30000);
}

function submitReply(){
	var isuser=eval(jQ("#userloginbutton").data("isuser"));
	if(!isuser){
		alert("评论请登录");
		return;
	}
	var content=jQ.trim(jQ("#replycontent").val());
	if(content==null||content.length==0){
		jQ("#replyzoneerror").empty().append("回复内容不能为空。");
	}else{
		if(content.length>255){
			jQ("#replyzoneerror").empty().append("回复内容不能超过255个字符。");
		}else{
			jQ.ajax({
				type: "POST",
				url:"eventAjax!addreply.action",
				data:{
					eventid:eval(jQ("#clip-contentlist").data("eventid")),
					content:content
				},
				success:function(data){
					if(data!=null){
						var dataObj=eval("("+data+")");//转换为json对象
						if(dataObj.result){
							var name="我";
							var replystr=formateDetailTimeWithhourmin(dataObj.replytime);
							var user_url=jQ("#user_url").css("background-image");
							var uid=jQ("#user_url").data("uid");
							var tmp="<li class='leave_msg'>";
							tmp+="<dt>";
							tmp+="<a href='"+jQ("#ctxVal").val()+"/myclip/user.html?"+uid+"' style='background-image:"+user_url+"' class=\"logo\"></a>";
							tmp+="<span class='fid'>";
								tmp+=name;
							tmp+="</span>";
							tmp+="<div>";
							tmp+=htmlData(content);
							tmp+="</div>";
							tmp+="<span class='time'>";
							tmp+=replystr;
							tmp+="</span></dt>";
							tmp+="</li>";
							jQ("#clipevent-messages").append(tmp);
							jQ("#replycontent").val("");
						}else{
							jQ("#replyzoneerror").empty().append(dataObj.msg);
						}
					}
				}
			});
		}
	}
}

function HTMLEnCode(str) {
	var s = "";
	if (str.length == 0)
		return "";
	s = str.replace(/&/g, "&gt;");
	s = s.replace(/</g, "&lt;");
	s = s.replace(/>/g, "&gt;");
	s = s.replace(/    /g, "&nbsp;");
	s = s.replace(/\'/g, "&#39;");
	s = s.replace(/\"/g, "&quot;");
	s = s.replace(/\n/g, "<br>");
	return s;
}
function HTMLDeCode(str) {
	var s = "";
	if (str.length == 0)
		return "";
	s = str.replace(/&gt;/g, "&");
	s = s.replace(/&lt;/g, "<");
	s = s.replace(/&gt;/g, ">");
	s = s.replace(/&nbsp;/g, "    ");
	s = s.replace(/&#39;/g, "\'");
	s = s.replace(/&quot;/g, "\"");
	s = s.replace(/<br>/g, "\n");
	return s;
}

function getUniqueParameter(){
    var paramStr=location.search;
    if(paramStr.length==0)return null;
    if(paramStr.charAt(0)!='?')return null;
    paramStr=unescape(paramStr);
    paramStr=paramStr.substring(1);
    if(paramStr.length==0)return null;
    return paramStr;
}
function htmlData(str){
	if(str==null||str.length==0)
		return "<i>暂无</i>";
	else{
		var tmp=jQ("#tools").text(str).html();
		jQ("#tools").empty();
		return tmp;
		
	}
}

function getTypeName(eng){
	if(eng=='other'){
		return "其他";
	}else if(eng=='work'){
		return "工作";
	}else if(eng=='socal'){
		return "社交";
	}else if(eng=='sect'){
		return "私人";
	}
}

function formateSmallDetailTime(day){
	return day.pattern("MMdd");
}

function formateDetailTimeWithhourmin(daytime){
	var day=new Date();
	day.setTime(daytime);
	return day.pattern("yyyy-MM-dd HH:mm");
}